package com.hazardSoft.eStore.entities;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Transient;

import com.hazardSoft.eStore.utils.QueryConstants;

@Entity
@NamedQueries({
	@NamedQuery(name = QueryConstants.QUERY_LIST_OFFICES, query = "FROM Office o ORDER BY o.name ASC"),
	@NamedQuery(name = QueryConstants.QUERY_SEARCH_OFFICE_BY_NAME, query = "FROM Office offi WHERE offi.name=?1")
})
public class Office implements Serializable {
	@Id
	private Integer id;

	@Lob
	private String name;

	@Lob
	private String address;

	@Lob
	private byte[] image;

	@Lob
	private String imagePath;

//	@OneToMany(mappedBy="office")
	@Transient
	private Collection<User> userCollection;

//	@OneToMany(mappedBy="office")
	@Transient
	private Collection<Inventory> inventoryCollection;

	@ManyToOne
	@JoinColumn(name="city")
	private City city;

	private static final long serialVersionUID = 1L;

	public Office() {
		super();
	}

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public byte[] getImage() {
		return this.image;
	}

	public void setImage(byte[] image) {
		this.image = image;
	}

	public String getImagePath() {
		return this.imagePath;
	}

	public void setImagePath(String imagePath) {
		this.imagePath = imagePath;
	}

	public Collection<User> getUserCollection() {
		return this.userCollection;
	}

	public void setUserCollection(Collection<User> userCollection) {
		this.userCollection = userCollection;
	}

	public Collection<Inventory> getInventoryCollection() {
		return this.inventoryCollection;
	}

	public void setInventoryCollection(Collection<Inventory> inventoryCollection) {
		this.inventoryCollection = inventoryCollection;
	}

	public City getCity() {
		return this.city;
	}

	public void setCity(City city) {
		this.city = city;
	}

	public String toString(){
		StringBuffer officeString = new StringBuffer();
		
		officeString.append("id: ["+this.getId()+"] ");
		officeString.append("name: ["+this.getName()+"] ");
		officeString.append("address: ["+this.getAddress()+"] ");
		officeString.append("city: ["+this.getCity()+"] ");
		officeString.append("imagePath: ["+this.getImagePath()+"] ");
		
		return officeString.toString();
	}
	public boolean equals(Object object){
		if (object == null) {
			return false;
		}
		if (!(object instanceof Office)) {
			return false;
		}
		Office office = (Office) object;
		
		if (office.getId() == null) {
			return false;
		} else {
			if (!(this.getId().equals(office.getId()))) {
				return false;
			}
		}
		
		return true;
	}
}
